import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { defHttp } from '/@/utils/http/axios';
import { reactive } from 'vue';
const showData = reactive({
    show:false,
  });
export const columns : BasicColumn[] = [
  {
    title: '接入编号',
    dataIndex: 'accessId'
  },
  {
    title: '接入名称',
    dataIndex: 'accessName'
  },
  {
    title: '协议名称',
    dataIndex: 'protocolName'
  },
  {
    title: '网络组件',
    dataIndex: 'networkName'
  },
  {
    title: '接入网关描述',
    dataIndex: 'accessRemark'
  },
  {
    title: '创建时间',
    dataIndex: 'createTime'
  },
];

export const searchFormSchema : FormSchema[] = [

  {
    label: '接入名称',
    field: 'accessName',
    component: 'Input'
  },
  {
    label: '协议名称',
    field: 'protocolId',
    component: 'ApiSelect',
    componentProps: {
      api: () => defHttp.get({ url: '/operation/operationNetwork/list' }),
      //数值转成String
      numberToString: false,
      //标题字段
      labelField: 'networkName',
      //值字段
      valueField: 'networkId',
      //请求参数
      params: {},
      //返回结果字段
      resultField: 'records',
    },
  },
  {
    label: '网络组件',
    field: 'networkId',
    component: 'ApiSelect',
    componentProps: {
      api: () => defHttp.get({ url: '/operation/operationNetwork/list' }),
      //数值转成String
      numberToString: false,
      //标题字段
      labelField: 'networkName',
      //值字段
      valueField: 'networkId',
      //请求参数
      params: {},
      //返回结果字段
      resultField: 'records',
    },
  },
];

export const formSchema : FormSchema[] = [
  // TODO 主键隐藏字段，目前写死为ID
  { label: '', field: 'accessId', component: 'InputNumber', show: false },
  { label: '', field: 'isEdit', component: 'InputNumber', show: false },

  {
    label: '接入名称',
    field: 'accessName',
    component: 'Input',
    rules: [{ required: true, message: "请输入接入名称" }],
    dynamicDisabled: ({ values }) => {
      if (values.isEdit != undefined && values.isEdit == true) {
        return true
      } else {
        return false
      }
    },
  },
  {
    label: '网络组件',
    field: 'networkId',
    component: 'ApiSelect',
    componentProps: {
      api: () => defHttp.get({ url: '/dictCommon/getNetworkList' }),
      //数值转成String
      numberToString: false,
      //标题字段
      labelField: 'networkName',
      //值字段
      valueField: 'networkId',
      //请求参数
      params: {},
      //返回结果字段
      resultField: 'records',
      onChange: (e) => {
        if(e == 1){
            showData.show = false
        }else{
            showData.show = true
        }
      },
    },
    rules: [{ required: true, message: "请选择网络组件" }],
    dynamicDisabled: ({ values }) => {
      if (values.isEdit != undefined && values.isEdit == true) {
        return true
      } else {
        return false
      }
    },
  },
  {
    label: '协议名称',
    field: 'protocolId',
    defaultValue: '',
    component: 'ApiSelect',
    // rules: [{ required: true, message: "请选择协议名称" }],
    componentProps: {
      api: () => defHttp.get({ url: '/dictCommon/getProtocolList' }),
      //数值转成String
      numberToString: false,
      //标题字段
      labelField: 'protocolName',
      //值字段
      valueField: 'protocolId',
      //请求参数
      params: {},
      //返回结果字段
      resultField: 'records',
    },
    dynamicDisabled: ({ values }) => {
      if (values.isEdit != undefined && values.isEdit == true) {
        return true
      } else {
        return false
      }
    },
  },
  {
    label: '接入网关描述',
    field: 'accessRemark',
    component: 'Input',
    dynamicDisabled: ({ values }) => {
      if (values.isEdit != undefined && values.isEdit == true) {
        return true
      } else {
        return false
      }
    },
  }
];
export {showData}